package TCP;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.SocketHandler;

public class Client {

    String ip;
    int sort;

    public Client(String ip, int sort) {
        this.ip = ip;
        this.sort = sort;
    }
    public void Start() throws IOException {
        Scanner scanner=new Scanner(System.in);
        Socket socket=new Socket(ip,sort);
        System.out.println("客户端建立");
        while (true){
            String request=scanner.nextLine();
            OutputStream outputStream= socket.getOutputStream();
            PrintWriter printWriter=new PrintWriter(outputStream);
            printWriter.println(request);
            System.out.println("客户端发送"+request);
            printWriter.flush();
            InputStream inputStream= socket.getInputStream();
            Scanner scanner1=new Scanner(inputStream);
            String reponse=scanner1.next();
            System.out.println("服务器回应："+reponse);
        }
    }

    public static void main(String[] args) throws IOException {
        Client client=new Client("127.0.0.1",9090);
        client.Start();
    }
}
